<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <my-element>别点，会爆炸！</my-element>
</body>
<script>
  class MyElement extends HTMLElement{
    constructor(){
      super();
    }
    boom(){
      this.dispatchEvent(new Event('boom'));
    }
  }

  customElements.define('my-element',MyElement);

  document.querySelector('my-element').addEventListener('boom',e=>{
    console.log('boom!!!');
  });

  setTimeout(document.querySelector('my-element').boom,3000);
</script>
</html>